<?php

/**
 * Radcodes - SocialEngine Module
 *
 * @category   Application_Extensions
 * @package    Cmspage
 * @copyright  Copyright (c) 2009-2010 Radcodes LLC (http://www.radcodes.com)
 * @license    http://www.radcodes.com/license/
 * @version    $Id$
 * @author     Vincent Van <vincent@radcodes.com>
 */

class Cmspage_Form_Search extends Radcodes_Lib_Fields_Form_Search {
	protected $_fieldType = 'cmspage';
	
	public function init() {
		//parent::init();
		

		$this->loadDefaultDecorators ();
		
		$this->getDecorator ( 'HtmlTag' )->setOption ( 'class', 'browsecmspages_criterian cmspages_browse_filters' )->setOption ( 'id', 'filter_form' );
		
		$this->setAttribs ( array ('id' => 'filter_form', 'class' => 'global_form_box cmspages_browse_filters' ) )->setMethod ( 'get' )->setAction ( Zend_Controller_Front::getInstance ()->getRouter ()->assemble ( array (), 'cmspage_browse', true ) );
		
		// Generate
		$this->generate ();
		
		// Add custom elements
		$this->getAdditionalOptionsElement ();
		
		foreach ( $this->getFieldElements () as $fel ) {
			if ($fel instanceof Zend_Form_Element) {
				
				$fel->clearDecorators ();
				$fel->addDecorator ( 'ViewHelper' );
				Engine_Form::addDefaultDecorators ( $fel );
			
			} else if ($fel instanceof Zend_Form_SubForm) {
				$fel->clearDecorators ();
				$fel->setDescription ( '<label>' . $fel->getDescription () . '</label>' );
				$fel->addDecorator ( 'FormElements' )->addDecorator ( 'HtmlTag', array ('tag' => 'div', 'id' => $fel->getName () . '-element', 'class' => 'form-element' ) )->addDecorator ( 'Description', array ('tag' => 'div', 'class' => 'form-label', 'placement' => 'PREPEND', 'escape' => false ) )->addDecorator ( 'HtmlTag2', array ('tag' => 'div', 'id' => $fel->getName () . '-wrapper', 'class' => 'form-wrapper browse-range-wrapper' ) );
			
			}
		}
	
	}
	
	public function getAdditionalOptionsElement() {
		$i = - 100;
		
		$this->addElement ( 'Text', 'search', array ('label' => 'Keyword', 'order' => $i ++ ) );
		
		$categories = Engine_Api::_ ()->cmspage ()->getCategories ();
		$categories_prepared = Engine_Api::_ ()->cmspage ()->convertCategoriesToArray ( $categories );
		$categories_prepared = array ("" => "All Categories" ) + $categories_prepared;
		
		$this->addElement ( 'Select', 'category', array ('label' => 'Category', 'order' => $i ++, 'filters' => array (new Radcodes_Lib_Filter_Null () ), 'multiOptions' => $categories_prepared, 'onchange' => 'this.form.submit();' )

		 );
		
		$this->addElement ( 'Select', 'show', array ('label' => 'Show', 'order' => $i ++, 'multiOptions' => array ('' => 'Everyone\'s Posts', '1' => 'Only My Friends\' Posts' ), 'onchange' => 'this.form.submit();' ) );
		
		$this->addElement ( 'Select', 'order', array ('label' => 'Browse By', 'order' => $i ++, 'multiOptions' => array ('creation_date' => 'Most Recent', 'view_count' => 'Most Viewed', 'comment_count' => 'Most Commented', 'modified_date' => 'Last Updated' ), 'onchange' => 'this.form.submit();' ) );
		
		$this->addElement ( 'Hidden', 'page', array ('order' => 500 ) );
		
		$this->addElement ( 'Hidden', 'tag', array ('order' => 501 ) );
		
		$this->addElement ( 'Button', 'done', array ('label' => 'Search', 'onclick' => 'this.form.submit();', 'order' => 1000 ) );
	}
}